﻿using System.Xml.Linq;
using Engine;


namespace Game
{
    public class CSWidget : CanvasWidget
    {
        public ComponentPlayer m_componentPlayer;

        public SubsystemNK m_subsystemHL;

        public ComponentMiner componentMiner;

        public ButtonWidget m_CSButton;
        public ButtonWidget m_CS1Button;
        public ButtonWidget m_CS2Button;
        public ButtonWidget m_CS3Button;
        public ButtonWidget m_CS4Button;
        public ButtonWidget m_CS5Button;



        public SliderWidget m_countSlider;

        public int Count = 1;

        public int ItemValue = 0;

        public SubsystemGameInfo m_subsystemGameInfo;
        public SubsystemTime subsystemTime;
        //下面是新人物状态按钮系统
        public CSWidget(ComponentPlayer componentPlayer, SubsystemNK subsystemHL)
        {
            m_componentPlayer = componentPlayer;
            m_subsystemHL = subsystemHL;
            XElement node = ContentManager.Get<XElement>("Widgets/cs");
            LoadContents(this, node);
            m_CSButton = Children.Find<ButtonWidget>("CSButton");
            m_CS2Button = Children.Find<ButtonWidget>("CS2Button");
            m_CS1Button = Children.Find<ButtonWidget>("CS1Button");
            m_CS3Button = Children.Find<ButtonWidget>("CS3Button");
            m_CS4Button = Children.Find<ButtonWidget>("CS4Button");
            m_CS5Button = Children.Find<ButtonWidget>("CS5Button");

            m_countSlider = Children.Find<SliderWidget>("CountSlider");
            m_countSlider.MinValue = 0f;
            m_countSlider.MaxValue = 10000f;
            m_countSlider.Granularity = 1f;
            m_countSlider.Value = Count;
        }

        public override void Update()
        {
            NK9 nk = m_componentPlayer.Entity.FindComponent<NK9>();
            int activeBlockValue = m_componentPlayer.ComponentMiner.ActiveBlockValue;
            int num = Terrain.ExtractContents(activeBlockValue);
            int activeBlockValue2 = m_componentPlayer.ComponentMiner.Inventory.GetSlotCount(activeBlockValue);
            int num2 = Terrain.ExtractContents(activeBlockValue2);
            float Money = m_subsystemHL.Money;

            Count = MathUtils.Clamp((int)m_countSlider.Value, 1, 10000);
            int Count2 = Count;
            Count2 = (int)m_subsystemHL.Money;
            m_countSlider.Text = "人物坐标:" + m_componentPlayer.ComponentBody.Position;
            if (m_CSButton.IsClicked)
            {
                m_componentPlayer.PlayerData.SpawnPosition = m_componentPlayer.ComponentBody.Position + new Vector3(0f, 0.1f, 0f);
                m_componentPlayer.ComponentGui.DisplaySmallMessage("保存重生点成功", Color.White, blinking: true, playNotificationSound: false);
            }
            if (m_CS1Button.IsClicked)
            {
                m_subsystemHL.CS2 = m_componentPlayer.ComponentBody.Position;
                m_componentPlayer.ComponentGui.DisplaySmallMessage("保存坐标成功", Color.White, blinking: true, playNotificationSound: false);
            }
            if (m_CS2Button.IsClicked)
            {
                m_subsystemHL.CS3 = m_componentPlayer.ComponentBody.Position;
                m_componentPlayer.ComponentGui.DisplaySmallMessage("保存坐标成功", Color.White, blinking: true, playNotificationSound: false);
            }


            if (m_CS3Button.IsClicked)
            {
                if (m_componentPlayer.PlayerData.SpawnPosition.X != 0)
                {
                    m_componentPlayer.ComponentBody.Position = m_componentPlayer.PlayerData.SpawnPosition;
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("传送成功", Color.White, blinking: true, playNotificationSound: false);
                }
                else
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("没有保存此坐标", Color.White, blinking: true, playNotificationSound: false);
                }
            }

            if (m_CS4Button.IsClicked)
            {
                if (m_subsystemHL.CS2.X != 0)
                {
                    m_componentPlayer.ComponentBody.Position = m_subsystemHL.CS2;
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("传送成功", Color.White, blinking: true, playNotificationSound: false);
                }
                else
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("没有保存此坐标", Color.White, blinking: true, playNotificationSound: false);
                }
            }

            if (m_CS5Button.IsClicked)
            {
                if (m_subsystemHL.CS3.X != 0)
                {
                    m_componentPlayer.ComponentBody.Position = m_subsystemHL.CS3;
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("传送成功", Color.White, blinking: true, playNotificationSound: false);
                }
                else
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("没有保存此坐标", Color.White, blinking: true, playNotificationSound: false);
                }
            }

        }
    }
}